home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.awt.Event;
- import java.io.IOException;
- import java.util.Enumeration;
- import java.util.Vector;
- import symantec.itools.db.pro.ConnectionInfo;
- import symantec.itools.db.pro.ListBinder;
- import symantec.itools.db.pro.ListLink;
- import symantec.itools.db.pro.ProjBinder;
- import symantec.itools.db.pro.ProjLink;
- import symantec.itools.db.pro.RelationView;
- import symjava.sql.SQLException;
-
- public class List extends java.awt.List implements ListLink, ProjLink {
- private ListBinder m_ListBinder;
- private ProjBinder m_ProjBinder;
- private boolean m_DynamicUpdate;
- private String m_BinderData;
- private String m_ScreenData;
- private boolean m_useStream;
- private boolean m_IsBound;
- private int m_treatBlankAs;
- private RelationView m_LookUpRelationView;
- private Vector m_JoinColumns;
- private ConnectionInfo m_Conn;
- private String m_SQL;
- private Vector staticItems;
-
- public List(RelationView lookupRV, ConnectionInfo conn) {
- this();
- this.m_LookUpRelationView = lookupRV;
- this.m_Conn = conn;
- }
-
- public List(int rows) {
- super(rows, false);
- this.m_DynamicUpdate = false;
- this.m_useStream = false;
- this.m_IsBound = false;
- this.staticItems = new Vector();
- this.m_ScreenData = new String();
- this.m_BinderData = new String();
- this.m_JoinColumns = new Vector();
- this.m_SQL = new String();
- }
-
- public List() {
- this(0);
- }
-
- public void init(ListBinder lBinder) {
- this.m_ListBinder = lBinder;
- }
-
- public void notifyListChange(ListBinder lBinder) {
- try {
- RelationView curRV = lBinder.getRelationView();
- ((java.awt.List)this).clear();
-
- while(curRV.next()) {
- super.addItem(curRV.getString(1));
- }
-
- Enumeration e = this.staticItems.elements();
-
- while(e.hasMoreElements()) {
- super.addItem((String)e.nextElement());
- }
-
- if (this.m_IsBound) {
- this.notifyDataChange(this.m_ProjBinder);
- return;
- }
- } catch (SQLException Ex) {
- this.raiseException("Exception from List.notifyDataChange.setString: " + ((Throwable)Ex).getMessage());
- }
-
- }
-
- public void init(ProjBinder binder) {
- this.m_ProjBinder = binder;
- this.setEditable(this.m_ProjBinder);
- }
-
- public void setTreatBlankAs(String blank) {
- if ((new String(blank)).toUpperCase().equals("DEFAULT")) {
- this.m_treatBlankAs = 0;
- } else if ((new String(blank)).toUpperCase().equals("NULL")) {
- this.m_treatBlankAs = 1;
- } else {
- if ((new String(blank)).toUpperCase().equals("EMPTY")) {
- this.m_treatBlankAs = 2;
- }
-
- }
- }
-
- public void setBinding(RelationView relView, String projection) {
- try {
- int projectionNumber = relView.findProjByName(projection);
- relView.bindProj(projectionNumber, this);
- } catch (SQLException Ex) {
- this.raiseException("SQLException from TextField.notifyDataChange.getStringValue: " + ((Throwable)Ex).getMessage());
- return;
- }
-
- this.m_IsBound = true;
- }
-
- public void setDynamicUpdate(boolean update) {
- this.m_DynamicUpdate = update;
- }
-
- public void notifyDataChange(ProjBinder binder) {
- if (binder != null) {
- this.m_ProjBinder = binder;
-
- try {
- if (binder.getRelationView().getCurrentRecordState() != 105) {
- if (binder.isReadable() && !binder.isNull()) {
- this.m_BinderData = binder.getStringValue();
- } else {
- this.m_BinderData = "";
- }
- } else {
- this.m_BinderData = "";
- }
- } catch (SQLException Ex) {
- this.raiseException("SQLException from TextField.notifyDataChange.getStringValue: " + ((Throwable)Ex).getMessage());
- } catch (IOException Ex) {
- this.raiseException("IOException from TextField.notifyDataChange.getStringValue: " + ((Throwable)Ex).getMessage());
- }
-
- if (this.m_BinderData == null) {
- this.m_BinderData = new String();
- }
-
- this.m_ScreenData = this.getText();
- if (!this.m_BinderData.equals(this.m_ScreenData)) {
- this.m_ScreenData = this.m_BinderData;
- this.setText(this.m_ScreenData);
- }
-
- this.setEditable(this.m_ProjBinder);
- }
- }
-
- public boolean lostFocus(Event evt, Object what) {
- if (this.m_IsBound) {
- this.notifySetData(this.m_ProjBinder);
- }
-
- return super.lostFocus(evt, what);
- }
-
- boolean notifyInputChanged(ProjBinder binder, String input) {
- if (!this.m_ScreenData.equals(input)) {
- this.m_ScreenData = input;
- }
-
- if (!this.m_BinderData.equals(this.m_ScreenData)) {
- this.m_BinderData = this.m_ScreenData;
-
- try {
- binder.setValueFromString(this.m_ScreenData, 0, this.m_treatBlankAs);
- } catch (SQLException Ex) {
- this.raiseException("SQLException from List.notifyInputChange: " + ((Throwable)Ex).getMessage());
- return false;
- } catch (IOException Ex) {
- this.raiseException("IOException from List.notifyInputChange: " + ((Throwable)Ex).getMessage());
- return false;
- }
- }
-
- return true;
- }
-
- public boolean notifySetData(ProjBinder binder) {
- return this.notifyInputChanged(binder, this.getText());
- }
-
- public boolean handleEvent(Event evt) {
- if (evt.id == 701 && this.m_IsBound) {
- this.notifySetData(this.m_ProjBinder);
- }
-
- return super.handleEvent(evt);
- }
-
- void setText(String text) {
- boolean bitemFound = false;
-
- for(int index = 0; index < ((java.awt.List)this).countItems(); ++index) {
- if (text.equals(((java.awt.List)this).getItem(index))) {
- ((java.awt.List)this).select(index);
- ((java.awt.List)this).makeVisible(index);
- bitemFound = true;
- return;
- }
-
- if (!bitemFound && ((java.awt.List)this).getSelectedIndex() != -1) {
- ((java.awt.List)this).deselect(((java.awt.List)this).getSelectedIndex());
- }
- }
-
- }
-
- void setEditable(ProjBinder binder) {
- boolean isWritable = false;
-
- try {
- if (binder != null) {
- RelationView rv = binder.getRelationView();
- if (rv != null && rv.getCurrentRecordState() != 105) {
- isWritable = binder.isWritable();
- return;
- }
- }
- } catch (SQLException Ex) {
- this.raiseException(((Throwable)Ex).getMessage());
- }
-
- }
-
- String getText() {
- String[] selectedItems = ((java.awt.List)this).getSelectedItems();
- return selectedItems.length == 1 ? selectedItems[0] : "";
- }
-
- void raiseException(String text) {
- System.out.println(text);
- }
-
- public void join(String columnName) throws SQLException {
- int colID = this.m_LookUpRelationView.findProjByName(columnName);
- if (this.m_JoinColumns == null) {
- this.m_JoinColumns = new Vector();
- }
-
- this.m_JoinColumns.addElement(new Integer(colID));
- }
-
- public void setSQL(String sql) throws SQLException {
- this.m_SQL = sql;
- }
-
- public void bindList() throws SQLException {
- this.m_LookUpRelationView.bindList(this.m_Conn, this.m_SQL, this, this.m_JoinColumns);
- }
-
- public synchronized void addItem(String item) {
- super.addItem(item, -1);
- this.staticItems.addElement(item);
- if (this.m_IsBound) {
- this.notifyDataChange(this.m_ProjBinder);
- }
-
- }
- }
-